# encoding: utf-8
class Location < ActiveRecord::Base
  attr_accessible :name, :search_name
  validates_uniqueness_of :name
  
  # Searches the search_name column
  #
  # * *Args*    :
  #   - +term+ -> the search term
  # * *Returns* :
  #   - 50 first locations that matches the search term
  #
  def self.search(term)
    if term
      term = term.gsub("*", "")
      search_term = "%" + term.fuzzify + "%"
      find(:all, :conditions => ['search_name LIKE ?', search_term], :limit => 50)
    else
      nil
    end
  end
end
